package com.autologistics.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.autologistics.model.Goodsorder;
import com.autologistics.model.GoodsorderId;

public class GoodsorderDaoImpl implements GoodsorderDao{
	HibernateTemplate hibTemplate;
	
	public HibernateTemplate getHibTemplate() {
		return hibTemplate;
	}

	public void setHibTemplate(HibernateTemplate hibTemplate) {
		this.hibTemplate = hibTemplate;
	}

	public void save(GoodsorderId goi){
		Goodsorder go = new Goodsorder(goi);
		hibTemplate.save(go);
	}
	public GoodsorderId getGoodsorderByOrderId(int id){
		String hql = "from Goodsorder where ordertable.id=?";
		List<Goodsorder> list=hibTemplate.find(hql,id);
		return list.get(0).getId();
	}
	public List<GoodsorderId> getGoodsorderByGoodsId(int id){
		String hql = "from Goodsorder where goods.id=?";
		List<Goodsorder> list=hibTemplate.find(hql,id);
		List<GoodsorderId> goi=new ArrayList<GoodsorderId>();
		for (Goodsorder go:list)
			goi.add(go.getId());
		return goi;
	}
}
